/*
 * Copyright 2017 Baiyyy
 * @(#)DeviceController.java
 */

package com.byyy.ccts.modules.cc.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeFilter;
import com.byyy.ccts.core.common.controller.BaseCRUDController;
import com.byyy.ccts.core.model.PageJson;
import com.byyy.ccts.core.query.annotation.PageableDefaults;
import com.byyy.ccts.core.query.data.PropertyPreFilterable;
import com.byyy.ccts.core.query.data.Queryable;
import com.byyy.ccts.core.query.utils.QueryableConvertUtils;
import com.byyy.ccts.core.query.wrapper.EntityWrapper;
import com.byyy.ccts.core.security.shiro.authz.annotation.RequiresPathPermission;
import com.byyy.ccts.core.utils.StringUtils;
import com.byyy.ccts.modules.cc.entity.ccts.TAChillCar;
import com.byyy.ccts.modules.cc.entity.ccts.TADevice;
import com.byyy.ccts.modules.cc.service.IChillCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 设备信息
 * Created by DELL on 2018-5-14.
 */
@Controller
@RequestMapping("${admin.url.prefix}/cc/chillcar")
@RequiresPathPermission("cc:chillcar")
public class ChillCarController extends BaseCRUDController<TAChillCar, String> {

    @Autowired
    private IChillCarService chillCarService;

    /**
     * 冷藏车列表
     * @param model
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="carInfoList", method = RequestMethod.GET)
    public String deviceInfoList(Model model, HttpServletRequest request, HttpServletResponse response) {
        return display("../carinfo/list");
    }

    /**
     * 根据页码和每页记录数，以及查询条件动态加载数据
     *
     * @param request
     * @param response
     * @throws java.io.IOException
     */
    @RequestMapping(value = "carInfoAjaxList", method = { RequestMethod.GET, RequestMethod.POST })
    public void deviceAjaxList(Queryable queryable, PropertyPreFilterable propertyPreFilterable, HttpServletRequest request,
                               HttpServletResponse response) throws IOException {
        EntityWrapper<TAChillCar> entityWrapper = new EntityWrapper<TAChillCar>(entityClass);
        preAjaxList(queryable,entityWrapper, request, response);
        propertyPreFilterable.addQueryProperty("id");
        // 预处理
        QueryableConvertUtils.convertQueryValueToEntityValue(queryable, entityClass);
        SerializeFilter filter = propertyPreFilterable.constructFilter(entityClass);
        PageJson<TAChillCar> pagejson = new PageJson<TAChillCar>(this.chillCarService.carInfoList(queryable, entityWrapper));
        String content = JSON.toJSONString(pagejson, filter);
        StringUtils.printJson(response, content);
    }

}
